extends CharacterBody2D_Unit


@onready var move: MoveComponent = $CharacterComponent/Move/MoveComponent
@onready var face: MoveComponent = $CharacterComponent/Face/MoveComponent
@onready var body: AnimatedSprite2D = $AnimatedSprite2D

@onready var nine_patch_rect_knapsack: NinePatchRect = $CanvasLayer/NinePatchRect_Knapsack
@onready var nine_patch_rect_equip: NinePatchRect = $CanvasLayer/NinePatchRect_Equip
@onready var equip_grid_container: GridContainer = $CanvasLayer/GridContainer


func _physics_process(delta: float) -> void:
    if move.is_moving():
        NodeHelper.play_animation(body, "move", sign(move.direction.x) != sign(face.direction.x))
    else:
        NodeHelper.play_animation(body, "idle")

func _on_texture_button_pressed() -> void:
    nine_patch_rect_knapsack.visible = !nine_patch_rect_knapsack.visible

func _on_grid_container_item_rect_changed() -> void:
    if nine_patch_rect_equip:
        nine_patch_rect_equip.size.x = equip_grid_container.size.x + 48
        nine_patch_rect_equip.position.x = equip_grid_container.position.x - 24
